﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Model
{
  public class Tips : MonoBehaviour
  {
    public Text text;
    public RectTransform rectTransform;
    public Camera UICamera;
    public RectTransform Canvas;
    public Vector2 Margin;

    private void LateUpdate()
    {
      if (gameObject.activeInHierarchy)
      {
        Vector2 localPoint;
        if (RectTransformUtility.ScreenPointToLocalPointInRectangle(Canvas, Input.mousePosition, UICamera, out localPoint))
        {
          localPoint.x += Margin.x;
          localPoint.y += Margin.y;
          transform.localPosition = localPoint;
        }
      }
    }

    public void Show(ItemEntity item)
    {
      text.text = item.ToString();
      gameObject.SetActive(true);
    }

    public void Hide()
    {
      gameObject.SetActive(false);
    }
  }
}
